﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sac.Web;
using System.Web.Security;

public partial class RootMenu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CreateRootTable();
    }

    protected void CreateRootTable()
    {
        MenuTreeOperate RootMenu = new MenuTreeOperate();
        List<MenuTree> RootList = new List<MenuTree>();
        RootList = RootMenu.GetRootMenuList();
        TableRow trRoot = new TableRow();
        
        foreach (MenuTree node in RootList)
        {
            TableCell CellSpace = new TableCell();
            CellSpace.Text = "&nbsp;&nbsp;|&nbsp;&nbsp;";
            HyperLink link = new HyperLink();
            link.Text =  node.Menu_Name;
            if (RootMenu.HasChild(node.ID_key.ToString()))
            {
                link.NavigateUrl = "MainPage.aspx?menuid=" + node.ID_key + "&menuurl=" + Server.UrlEncode(node.Menu_Url);
            }
            else
            {
                link.NavigateUrl = node.Menu_Url;
            }
            link.Target = "myFrMain";
            link.Font.Underline = false;
            link.ForeColor = System.Drawing.Color.White;
            TableCell NodeCell = new TableCell();
            NodeCell.Controls.Add(link);
            trRoot.Cells.Add(CellSpace);
            trRoot.Cells.Add(NodeCell);
        }
        tabRootMenu.Rows.Add(trRoot);
        lblUserWelcome.Text = "欢迎您！" + Session["UserName"].ToString() + "&nbsp;";
    }
    protected void linkBtnLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session["UserName"] = null;
        Session["RolePower"] = null;
        Response.Write("<script type='text/javascript'>top.window.location.href='Login.aspx'; </script>");
    }
}
